import { EntityManager, MikroORM } from '@mikro-orm/core';
import { InjectEntityManager, InjectMikroORM } from '@mikro-orm/nestjs';
import { Body, Controller, Post, Req } from '@nestjs/common';
import { knext } from 'knext';
import { Users } from '@entities/Users';
import { request } from 'http';
import * as _ from 'lodash'
import { JsonApiResponse } from '@utils/json.api.response';

@Controller('user')
export class UserController {
    constructor(
        @InjectMikroORM('zp')
        private readonly orm : MikroORM,
        @InjectEntityManager('zp')
        private readonly em : EntityManager
        
    ){}


    @Post('baseInfo')
    async baseInfo(@Req() request,@Body() formData){
        const knex = knext(this)

        const userId = request.user.id

        const result = await knex.fromORM(Users)
        .where('id',userId)
        .update({
            ... _.pick(formData,'nickname','sex','head_icon_url','phone_number','name')
        })

        return JsonApiResponse.OK()
    }
}
